package com.hmall.item.config;

import com.hmall.item.constants.ItemMqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    //交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(ItemMqConstants.EXCHANGE_NAME);
    }

    //插入队列
    @Bean
    public Queue insertQueue(){
        return new Queue(ItemMqConstants.INSERT_QUEUE_NAME);
    }
    //删除队列
    @Bean
    public Queue deleteQueue(){
        return new Queue(ItemMqConstants.DELETE_QUEUE_NAME);
    }
    //绑定
    @Bean
    public Binding insertBinding(){
        return BindingBuilder.bind(insertQueue()).to(topicExchange()).with(ItemMqConstants.INSERT_KEY);
    }
    //绑定
    @Bean
    public Binding deleteBinding(){
        return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with(ItemMqConstants.DELETE_KEY);
    }
}
